package app.models;

import org.javalite.activejdbc.Model;
import org.javalite.activejdbc.annotations.IdName;
import org.javalite.activejdbc.annotations.Table;

/**
 *
 * @author Kseniya Artsiukhova <kartsiukhova@productiveedge.com>
 */
@Table("books")
@IdName("book_id")
public class Book extends Model {

    static{
        validatePresenceOf("book_name").message("Please, provide your book name");
        validatePresenceOf("book_author").message("Please, provide your book author");
        validateNumericalityOf("number_of_pages").message("Please, provide your number of page");
        validatePresenceOf("book_format").message("Please, provide your book format");
    } 
    
    public void setBookId(Long bookId) {
        setLong("book_id", bookId);
    }

    public Long getBookId() {
        return getLong("book_id");
    }

    public void setBookName(String name) {
        setString("book_name", name);
    }

    public String getBookName() {
        return getString("book_name");
    }

    public void setBookAuthor(String author) {
        setString("book_author", author);
    }

    public String getBookAuthor() {
        return getString("book_author");
    }
    
    public void setNumberOfPages(Long numberOfPages) {
        setLong("number_of_pages", numberOfPages);
    }

    public Long getNumberOfPages() {
        return getLong("number_of_pages");
    }

    public void setBookFormat(String format) {
        setString("book_format", format);
    }

    public String getBookFormat() {
        return getString("book_format");
    }

    public void setGenreId(Long genreId) {
        setLong("genre_id", genreId);
    }

    public Long getGenreId() {
        return getLong("genre_id");
    }

    public static void deleteBook(Long id) {
        Book.delete("book_id = ?", id);
    }
}
